<?php

namespace Tasker\Components;

abstract class BaseControl extends \Nette\Application\UI\Control
{

	/**
	 * Function is callable only from methods render<action>()
	 * @param string $action
	 */
	protected function setTemplate()
	{
		$dir = dirname($this->reflection->fileName);
		$backtrace = debug_backtrace();
		$method = $backtrace[1]['function'];
		if (\Nette\Utils\Strings::startsWith($method, 'render'))
		{
			$action = lcfirst(substr($method, strlen('render')));
			$this->template->setFile($dir . '/' . $action . '.latte');
		} else
		{
			throw new \Nette\InvalidArgumentException("Function setTemplate is callable only from methods render<action>()");
		}
	}

}
